package br.ufpe.ci.ip.projeto.config;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import org.ufpe.cin.ip.projeto.Dados.Enums.EnumTipoRepositorio;
import org.ufpe.cin.ip.projeto.Exceptions.UnexpectedRepositoryTypeException;

public final class Configurador {
	private static final Configurador INSTANCE = new Configurador();
	private static String tipoRepositorioEmConfig;
	
	public static final EnumTipoRepositorio tipoRepositorio = selecionarRepositorio();
	
	private Configurador() {}
	
	private static EnumTipoRepositorio selecionarRepositorio() {
		EnumTipoRepositorio aux = null;
		try {  
            FileReader lendo = new FileReader("Files/TXT/Configuration/Config.txt");  
            BufferedReader bufer = new BufferedReader(lendo);  
            String ler = null;  
            
           while ((ler = bufer.readLine()) != null) {  
        	   tipoRepositorioEmConfig = ler;
        	   
        	   if(tipoRepositorioEmConfig.equalsIgnoreCase("tad")){
        		   aux = EnumTipoRepositorio.TAD;
        	   } else if(tipoRepositorioEmConfig.equalsIgnoreCase("array")){
        		   aux = EnumTipoRepositorio.array;
        	   } else if(tipoRepositorioEmConfig.equalsIgnoreCase("arquivo")){
        		   aux = EnumTipoRepositorio.arquivo;
        	   } else{
        		   throw new UnexpectedRepositoryTypeException();
        	   }
           }  
            
           bufer.close();
            
        } catch (IOException e) {  
            e.printStackTrace();  
        } catch (UnexpectedRepositoryTypeException e) {
			e.printStackTrace();
		}  
		
		return aux;
	}

	public static Configurador getInstance(){
		return INSTANCE;
	}
	
//	public static void main(String[] args) {  
//		// TODO Auto-generated method stub  
//		try{  
//			Workbook workbook = Workbook.getWorkbook(new File("C:/"));  
//			Sheet sheet = workbook.getSheet(0);  
//
//			sheet.findCell("col1").getColumn();  
//			int c1 = sheet.findCell("col1").getColumn();  
//			int c2 = sheet.findCell("col2").getColumn();  
//			int c3 = sheet.findCell("col3").getColumn();  
//			Cell a1[] =sheet.getColumn(c1);  
//			Cell a3[] =sheet.getColumn(c2);  
//			Cell a4[] =sheet.getColumn(c3);  
//			System.out.print("inicio leitura");  
//			System.out.println("\n");  
//			System.out.println("inicio leitura celula");  
//			for(int i=0;i<a1.length;i++){  
//				if(a1[i].getContents().equals("")){  
//					i++;  
//				}else{  
//					System.out.println(a1[i].getContents()+"-"+a3[i].getContents()+"-"+a4[i].getContents());  
//				}  
//			}  
//			System.out.println("fim leitura coluna ");  
//			System.out.print("\n");  
//			int r1 = sheet.findCell("ti").getRow();  
//			Cell a5[] =sheet.getRow(r1);  
//			for(int i=0;i<a1.length;i++){  
//				if(a1[i].getContents().equals("")){  
//					i++;  
//				}else{  
//					System.out.print(a5[i].getContents()+" - ");  
//				}  
//			}  
//			System.out.print("\n");  
//			System.out.println("fim leitura");  
//			workbook.close();  
//		}catch(Exception e){  
//			System.err.println(e.getMessage());  
//		}  
//
//	}  

}  